/*package ai;

import graphics.engine.Camera;
import graphics.engine.ProgramShader;
import graphics.primitive.Circle;
import graphics.primitive.Disk;

import java.util.ArrayList;
import java.util.Iterator;

import mathematics.Matrix4x4;
import mathematics.PolygonMath;
import model.RoomModel;
import model.RoomType;

import utils.Point2D;
import utils.Point3D;
import utils.Segment;
import utils.Vector2D;
import utils.Vector3D;

public class WanderingBehaviour 
{
	private static ArrayList<Point2D> positions = new ArrayList<Point2D>();

	public static Point2D position = new Point2D(0,0);
	private static Vector2D velocity = new Vector2D();
	private static Vector2D steerForce = new Vector2D();
	private static Vector2D acceleration = new Vector2D();
	private static Vector2D wanderTarget = new Vector2D();

	private static float mass = 2;
	private static float maxSpeed = 5;
	private static float maxForce = 10;
	
	private static float wanderRadius = 20; //the radius of the circle
	private static float wanderDistance = 40;
	private static float wanderJitter = 5;
	
	private static Disk disk;
	private static Circle circle;

	private static Point2D circleCenterM = new Point2D();

	private static Vector2D pointOnCircle = new Vector2D();


	public WanderingBehaviour()
	{
	}	
	
	public static Point2D nextWanderingPosition(PolygonMath poly)
	{
		Point2D  oldPosition = new Point2D(WanderingBehaviour.position);

		Vector2D newSteerForce = Wander();
		newSteerForce = Vector2D.Truncate(newSteerForce, WanderingBehaviour.maxForce);
		WanderingBehaviour.steerForce = newSteerForce;

		WanderingBehaviour.acceleration = Vector2D.mult(newSteerForce, 1.0f / WanderingBehaviour.mass);
		WanderingBehaviour.velocity = Vector2D.Truncate(Vector2D.sum(WanderingBehaviour.velocity, WanderingBehaviour.acceleration), WanderingBehaviour.maxSpeed);
		
		Vector2D heading = WanderingBehaviour.velocity.normalized();
		 
		Point2D newPosition = Point2D.sum(oldPosition, WanderingBehaviour.acceleration);
		Point2D collisionPoint = Point2D.sum(oldPosition,Vector2D.mult(heading, 50 + Math.random() * 5));
		
	
		Segment seg = new Segment(oldPosition,collisionPoint);
		Point2D intersectionPoint = Segment.intersectionPoint(seg, poly);
		
		if(intersectionPoint != null)
		{
			WanderingBehaviour.position = oldPosition;
			return null;
		}
		WanderingBehaviour.position = newPosition;
		
		return newPosition;
	}
	
	//Those numbers can be changed to get other movement patterns. Those are the defaults used in the demo
	private static Vector2D Wander() 
	{
		Vector2D heading = WanderingBehaviour.steerForce.normalized();
		
		double randX = (Math.random() * 2.0 - 1) * WanderingBehaviour.wanderJitter;
		double randY = (Math.random() * 2.0 - 1) * WanderingBehaviour.wanderJitter;

		WanderingBehaviour.wanderTarget = Vector2D.sum(WanderingBehaviour.wanderTarget, new Vector2D((float)randX, (float)randY));
		WanderingBehaviour.wanderTarget = WanderingBehaviour.wanderTarget.normalized();
		WanderingBehaviour.wanderTarget =  Vector2D.mult(WanderingBehaviour.wanderTarget, WanderingBehaviour.wanderRadius / 2.0f);

		WanderingBehaviour.circleCenterM = new Point2D((heading.x() * WanderingBehaviour.wanderDistance) + WanderingBehaviour.position.x(), (heading.y() * WanderingBehaviour.wanderDistance) + WanderingBehaviour.position.y());
		WanderingBehaviour.pointOnCircle = new Vector2D(WanderingBehaviour.circleCenterM.x() + WanderingBehaviour.wanderTarget.x(), WanderingBehaviour.circleCenterM.y() + WanderingBehaviour.wanderTarget.y());

		Vector2D result = Vector2D.sum(WanderingBehaviour.pointOnCircle, new Vector2D(- WanderingBehaviour.position.x(), - WanderingBehaviour.position.y()));
		
		return result;
	}
	
	public static ArrayList<Point2D> generateBehaviour(RoomModel room, Point2D entryPoint, Point2D endPoint, long totalTime, ArrayList<Point2D> checkPoint, ArrayList<Integer> sleeps)
	{
		ArrayList<Point2D> trajectory = new ArrayList<Point2D>();
		trajectory.add(new Point2D((float)entryPoint.x(), (float)entryPoint.y()));
		
		Vector2D doorRoomCenterVector = new Vector2D(entryPoint, new Point2D(room.position));
		doorRoomCenterVector = doorRoomCenterVector.normalized();
		
		Point2D initialisingPoint = Point2D.sum(entryPoint, Vector2D.mult(doorRoomCenterVector, 15));

		trajectory.add(new Point2D((float)initialisingPoint.x(), (float)initialisingPoint.y()));
		
		WanderingBehaviour.position = initialisingPoint;
		
		for(int i = 0; i < totalTime; i++)
		{
			if(room.type == RoomType.Room)
			{
				Point2D currentPosition = WanderingBehaviour.nextWanderingPosition((PolygonMath)room.geometricShape);
			
			
				while(currentPosition == null)
				{
					currentPosition = WanderingBehaviour.nextWanderingPosition((PolygonMath)room.geometricShape);
				}
				trajectory.add(new Point2D((float)currentPosition.x(), (float)currentPosition.y()));
			}
			else
			{
				if(endPoint == null)
				{
					endPoint = new Point2D(room.position);
				}
				Point2D currentPosition = WanderingBehaviour.nextPathFollowingPosition((PolygonMath)room.geometricShape, entryPoint, endPoint);
				while(currentPosition == null)
				{
					currentPosition = WanderingBehaviour.nextPathFollowingPosition((PolygonMath)room.geometricShape, entryPoint, endPoint);
				}
				trajectory.add(new Point2D((float)currentPosition.x(), (float)currentPosition.y()));
						
			}
		}
		
		if(endPoint != null)
		{
			trajectory.add(new Point2D((float)endPoint.x(), (float)endPoint.y()));
		}
		return trajectory;
	}
	
	
	private static Point2D nextPathFollowingPosition(PolygonMath geometricShape, Point2D entryPoint, Point2D endPoint) {
		Point2D  oldPosition = new Point2D(WanderingBehaviour.position);

		Vector2D newSteerForce = PathFollowing(entryPoint, endPoint);
		newSteerForce = Vector2D.Truncate(newSteerForce, WanderingBehaviour.maxForce);
		WanderingBehaviour.steerForce = newSteerForce;

		WanderingBehaviour.acceleration = Vector2D.mult(newSteerForce, 1.0f / WanderingBehaviour.mass);
		WanderingBehaviour.velocity = Vector2D.Truncate(Vector2D.sum(WanderingBehaviour.velocity, WanderingBehaviour.acceleration), WanderingBehaviour.maxSpeed);
		
		Vector2D heading = WanderingBehaviour.velocity.normalized();
		 
		Point2D newPosition = Point2D.sum(oldPosition, WanderingBehaviour.acceleration);
		Point2D collisionPoint = Point2D.sum(oldPosition,Vector2D.mult(heading, 50 + Math.random() * 5));
		
	
		Segment seg = new Segment(oldPosition,collisionPoint);
		Point2D intersectionPoint = Segment.intersectionPoint(seg, geometricShape);
		
		if(intersectionPoint != null)
		{
			WanderingBehaviour.position = oldPosition;
			return null;
		}
		WanderingBehaviour.position = newPosition;
		
		return newPosition;
	}

	private static Vector2D PathFollowing(Point2D entryPoint, Point2D endPoint) 
	{
		Vector2D heading = WanderingBehaviour.steerForce.normalized();
		Vector2D globalDirection = new Vector2D(WanderingBehaviour.position, endPoint);
		globalDirection = globalDirection.normalized();
		globalDirection = Vector2D.mult(globalDirection, 5);
		
		double randX = (Math.random() * 2.0 - 1) * WanderingBehaviour.wanderJitter;
		double randY = (Math.random() * 2.0 - 1) * WanderingBehaviour.wanderJitter;

		WanderingBehaviour.wanderTarget = Vector2D.sum(WanderingBehaviour.wanderTarget, new Vector2D((float)randX, (float)randY));
		WanderingBehaviour.wanderTarget = WanderingBehaviour.wanderTarget.normalized();
		WanderingBehaviour.wanderTarget =  Vector2D.mult(WanderingBehaviour.wanderTarget, WanderingBehaviour.wanderRadius / 2.0f);

		WanderingBehaviour.circleCenterM = new Point2D((heading.x() * WanderingBehaviour.wanderDistance) + WanderingBehaviour.position.x(), (heading.y() * WanderingBehaviour.wanderDistance) + WanderingBehaviour.position.y());
		WanderingBehaviour.pointOnCircle = new Vector2D(WanderingBehaviour.circleCenterM.x() + WanderingBehaviour.wanderTarget.x(), WanderingBehaviour.circleCenterM.y() + WanderingBehaviour.wanderTarget.y());

		Vector2D result = Vector2D.sum(WanderingBehaviour.pointOnCircle, new Vector2D(- WanderingBehaviour.position.x(), - WanderingBehaviour.position.y()));

		double length = result.length();
		
		result = result.normalized();
		result = Vector2D.sum(result, globalDirection);
		result = Vector2D.mult(result, length);
		
		
		return result;	
	}
}*/
